package demo1;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class tenStudents06 {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new FileReader("tenStudents.txt"));
		String line;
		ArrayList<String> list = new ArrayList<>();
		while((line=br.readLine())!=null){
			list.add(line);
		}
		String[] arr= new String[list.size()];
		for(int i=0;i<list.size();i++){
			arr[i] = list.get(i);
		}
		br.close();
		System.out.println(list);
		ArrayList<String> list1 = new ArrayList<>();
		int index=0,count=0,num=1;
		if(true){
			BufferedReader br1 = new BufferedReader(new FileReader("name3.txt"));
			while((line=br1.readLine())!=null){
				
				System.out.println(line);
				String[] s= line.split(":");
				count =Integer.parseInt(s[0]);
				
				list1.add(s[1]);
			}
			
			if(count<10){
				
				list.removeAll(list1);
				br1.close();
				Random random = new Random();
				index = random.nextInt(10-count);
				System.out.println(list.get(index));
				count++;
				BufferedWriter bw=new BufferedWriter(new FileWriter(("name3.txt"),true));
				bw.write(count+":"+list.get(index));
				bw.newLine();
				bw.close();
			}
			
			else if(count>=10){
				
				System.out.println("第:"+num+":轮点名结束");
				System.out.println("第:"+(num+1)+":轮点名开始");
				list=list1;
				count = 0;
				num++;
				while(true){
					Scanner sc = new Scanner(System.in);
					System.out.println("按回车点名");
					String p = sc.nextLine();
					Random random1 = new Random();
					index = random1.nextInt(10-count);
					System.out.println(list.get(index));
					count++;
					list1.add(list.get(index));
					list.remove(index);
					if(count>9){
						System.out.println("第:"+num+":轮点名结束");
						System.out.println("第:"+(num+1)+":轮点名开始");
						list=list1;
						count=0;
						num++;
					}
					
				}
			}
		}
		
	}

}
